package com.bjpowernode.task;

import com.bjpowernode.api.service.IncomeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @description:
 * @author: panDeng_Zhu
 * @time: 2022/11/23 10:27
 * 定义方法，管理定时任务
 */

@Component("taskManger")
public class TaskManager {

    @DubboReference(interfaceClass = IncomeService.class, version = "1.0")
    private IncomeService incomeService;

    /**
     * 定时任务的方法
     * 1.public方法
     * 2.方法没有参数
     * 3.方法没有返回值
     */
   // @Scheduled(cron = "0/5 * * * * ?")
    public void testCron() {
        System.out.println("定时任务的：" + new Date());
    }

    //调用生成收益计划
   @Scheduled(cron = "0 0 2 * * ?")
    public void handleIncomePlan(){
        System.out.println("开始执行收益计划的定时任务");
        incomeService.generateIncomePlan();
    }

    //调用收益返还的计划
    @Scheduled(cron="0 0/20 * * * ?")
    public void handleIncomeBack(){
        System.out.println("开始执行收益返还计划的定时任务");
        incomeService.generateIncomeBack();
    }
}